/***************************************************************************
 *            declarations.h
 *
 *  Thu Sep 24 14:11:38 2009
 *  Copyright  2009  kdekorte
 *  <kdekorte@quad>
 ****************************************************************************/

/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Library General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301,  USA
 */

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <clutter/clutter.h>
#include <stdlib.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <clutter-gtk/clutter-gtk.h>
#include <clutter-gst/clutter-gst.h>
#include <glib/gi18n.h>
#include <gdk/gdkkeysyms.h>


#ifndef _DECLARATIONS_H
#define _DECLARATIONS_H

typedef struct _IdleData {
    gchar info[1024];
    gchar display_name[1024];
    gchar media_info[2048];
    gchar media_notification[2048];
    gchar url[1024];
    gchar af_export[1024];
    GMappedFile *mapped_af_export;
    gint windowid;
    gchar *device;
    gdouble percent;
    gdouble cachepercent;
    gint streaming;
    gchar progress_text[1024];
    gdouble volume;
    gint mplayer_volume;
    gboolean mute;
    gchar vol_tooltip[128];
    gint x;
    gint y;
    gint last_x;
    gint last_y;
    gint original_h;
    gint original_w;
    gint width;
    gint height;
    gboolean videopresent;
    gboolean audiopresent;
    gboolean fullscreen;
    gboolean showcontrols;
    gdouble position;
    gdouble length;
    glong byte_pos;
    gint chapters;
    gint brightness;
    gint contrast;
    gint gamma;
    gint hue;
    gint saturation;
    gchar demuxer[64];
    gchar video_format[64];
    gchar video_codec[16];
    gchar video_fps[16];
    gchar video_bitrate[16];
    gchar audio_codec[16];
    gchar audio_bitrate[16];
    gchar audio_samplerate[16];
    gchar audio_channels[16];
    gchar metadata[1024];
    gboolean fromdbus;
    gboolean window_resized;
    gboolean has_chapters;
    gboolean tmpfile;
    gboolean sub_visible;
    gint sub_demux;
    gint switch_audio;
    gboolean retry_on_full_cache;
    GFile *src;
    GFile *tmp;
    GCancellable *cancel;
    GMutex *caching;
    GCond *caching_complete;
} IdleData;

IdleData *idledata;


typedef struct _ListItem {
	gchar *uri;
	ClutterActor *display;
	ClutterActor *thumbnail;
	ClutterActor *details;
	GstTagList *tags;
	GList *languages;
	GList *subtitles;
} ListItem;

ListItem *listitem;
GList *playlist;
GList *currentitem;

gint video_width,video_height;
GtkWidget *window;
ClutterActor *media;
ClutterActor *stage;
GtkWidget *clutter, *main_menu;
GtkFixed *fixed;
GtkWidget *menuitem_file_details, *menuitem_file_open_recent, *menuitem_file_recent_items;
GtkWidget *menuitem_file, *menuitem_select, *menuitem_view, *menuitem_help;
GtkWidget *menu_file, *menu_select, *menu_view, *menu_help;
GtkWidget *menuitem_view_fullscreen, *menuitem_view_controls;
GtkWidget *menuitem_select_audio, *menuitem_select_subtitle;

GtkWidget *menuitem_view_aspect_default, *menuitem_view_aspect_16x9,
			*menuitem_view_aspect_16x10, *menuitem_view_aspect_4x3,
			*menuitem_view_aspect_follow;

GtkWidget *menu_subtitles, *menu_languages;

ClutterActor *control_cbox;
ClutterActor *ctracker, *cfullscreen, *cvolume, *cplay_pause;
ClutterActor *crewind, *cstop, *cforward;
ClutterLayoutManager *control_layout;
ClutterActor *control_background;
ClutterActor *control_group;

GstElement *pipeline;
GstElement *audio_sink;
GstElement *video_sink;

gdouble duration;
gboolean can_seek;


gboolean dontplaynext;
gboolean isfullscreen;
gdouble media_aspect;
gint control_id, source_id, embed_window;
gchar *rpconsole, *rpname;
gboolean control_instance;
gint window_width, window_height;
gboolean show_controls, disable_context_menu;
gint plugin_cache_size;
gint js_state;
gint verbose;
glong last_movement_time;
gboolean mouse_over_fixed;

gboolean autostart, showcontrols;

gboolean has_navigation;

GMutex *menu_update_mutex;

#define DRAG_NAME_0		"text/plain"
#define DRAG_INFO_0		0
#define DRAG_NAME_1		"text/uri-list"
#define DRAG_INFO_1		1
#define DRAG_NAME_2		"STRING"
#define DRAG_INFO_2		2

// found in dbus-interface
void dbus_open_by_hrefid(gchar * hrefid);
void dbus_open_next();
void dbus_cancel();
void dbus_reload_plugins();
void dbus_send_rpsignal(gchar * signal);
void dbus_send_rpsignal_with_int(gchar * signal, int value);
void dbus_send_rpsignal_with_double(gchar * signal, gdouble value);
void dbus_send_rpsignal_with_string(gchar * signal, gchar * value);
void dbus_send_event(gchar * event, gint button);
void dbus_unhook();
void dbus_enable_screensaver();
void dbus_disable_screensaver();

// found in support
gboolean add_item_to_playlist(gchar *uri);
gboolean clear_playlist();
void update_item_display(ListItem *item);

// found in callbacks
void bus_message_callback(GstBus * bus, GstMessage * message, gpointer data);
void element_changed_callback(GstElement * obj, gpointer data);
gboolean on_display_button_release_event(ClutterActor * actor, ClutterButtonEvent * event, gpointer data);
void video_sink_element_added(GstBin *video_sink, GstElement *element, gpointer data);
gboolean on_tracker_percentage_changed(GtkWidget * widget, gdouble percent, void *data);
gboolean on_window_delete_event(GtkWidget * widget, GdkEvent * event, void *data);
void menuitem_open_recent_item_activated(GtkRecentChooser * chooser, gpointer data);
gboolean on_fixed_enter_notify_event(GtkWidget *widget, GdkEventCrossing *event, gpointer data); 
gboolean on_fixed_leave_notify_event(GtkWidget *widget, GdkEventCrossing *event, gpointer data); 
void on_control_group_paint(ClutterActor *actor, gpointer data);
gboolean on_window_scroll_event(GtkWidget *widget, GdkEventScroll * event, gpointer data);

void audio_tags_changed_callback(GstElement *playbin, gint stream_id, gpointer data);
void text_tags_changed_callback(GstElement *playbin, gint stream_id, gpointer data);

typedef enum {
  GST_PLAY_FLAGS_VIDEO        = 0x01,
  GST_PLAY_FLAGS_AUDIO        = 0x02,
  GST_PLAY_FLAGS_TEXT         = 0x04,
  GST_PLAY_FLAGS_VIS          = 0x08,
  GST_PLAY_FLAGS_SOFT_VOLUME  = 0x10,
  GST_PLAY_FLAGS_NATIVE_AUDIO = 0x20,
  GST_PLAY_FLAGS_NATIVE_VIDEO = 0x40,
  GST_PLAY_FLAGS_DOWNLOAD     = 0x80
} GstPlayFlags;

#endif
